<template>
	<view>
		<!-- <Head>系统消息</Head> -->
		<view class="form_top_border"></view>
		<u-empty text="没有找到对应的数据" v-if="show_empty === true" />
		<view>
			<view class="box_1">
				<view class="item" v-for="(item, index) in dataset" :key="index">
					<view class="title">
						{{ item.type_text }}
						<view class="right_txt">{{ item.addtime | timeFilter }}</view>
					</view>
					<view class="content">
						<view class="c1">
							{{ item.content }}
						</view>
						<view v-if="item.inner_link" class="c2" @click="handlerDetail(item)">
							查看详情
						</view>
					</view>
				</view>
			</view>
			<!-- <van-list v-if="dataset.length > 0" @load="onLoad"></van-list> -->
			<u-loadmore class="u-loadmore" v-if="dataset.length >= params.pagesize" :status="finished_status" />
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		parseTime
	} from '@/utils/index'
	import http from '@/utils/http'
	import api from '@/api'
	export default {
		name: 'Msg',
		filters: {
			timeFilter(timestamp) {
				return parseTime(timestamp, '{y}-{m}-{d} {h}:{i}')
			}
		},
		data() {
			return {
				dataset: [],
				finished_status: 'loadmore',
				show_empty: false,
				params: {
					page: 1,
					pagesize: 10
				}
			}
		},
		created() {
			this.fetchData(true)
		},
		onReachBottom() {
			this.params.page++
			this.fetchData(false)
		},
		methods: {
			handleTips() {
				this.$refs.uToast.show({
					title: '功能正在开发中'
				})
			},
			fetchData(init) {
				if (init === true) {
					this.params.page = 1
				} else {
					this.finished_status = 'nomore'
				}
				http
					.get(api.member_msglist, this.params)
					.then(res => {
						if (init === true) {
							this.dataset = [...res.data.data.items]
						} else {
							this.dataset = this.dataset.concat(res.data.data.items)
						}
						// 数据全部加载完成
						if (res.data.data.items.length < this.params.pagesize) {
							this.finished_status = 'nomore'
							if (init === false) {
								this.finished_status = 'nomore'
							} else if (res.data.data.items.length == 0) {
								this.show_empty = true
							}
						}
					})
					.catch(() => {})
			},
			handleClick(path) {
				uni.navigateTo({
					url: path
				})
			},
			handlerDetail(item) {
				if (item.utype == 1) {
					switch (item.inner_link) {
						case 'resumeshow':
							uni.navigateTo({
								url: '/commonViews/ResumeShow?id=' + item.inner_link_params
							})
							break
						case 'job_manage':
							this.handleClick('/company/JobList')
							break
						case 'company_index':
							this.handleClick('/company/CompanyIndex')
							break
						case 'company_auth':
							this.handleClick('/company/AccountManage/Auth')
							break
						case 'ordershow':
							this.handleClick('/commonViews/service/OrderList')
							break
						case 'im':
							// this.handleClick('/views/im/ImList')
							this.handleTips()
							break
						case 'service':
							// this.handleClick('/company/Service/BuyService?type=service')
							this.handleTips()
							break
						case 'coupon':
							this.handleClick('/company/Service/Coupon')
							break
						case 'service_setmeal':
							// this.handleClick('/company/Service/BuyService?type=setmeal')
							this.handleTips()
							break
						case 'interview_list':
							this.handleClick('/company/ResumeManagement/ResumeInterviewInvitation')
							break
						case 'interview_list_video':
							this.handleClick('/company/ResumeManagement/ResumeVideoInvitation')
							break
						case 'recommend_resumelist':
							this.handleClick('/company/Recommend')
							break
						default:
							break
					}
				} else {
					switch (item.inner_link) {
						case 'companyshow':
							uni.navigateTo({
								url:'/commonViews/CompanyShow?id='+item.inner_link_params
							})
							break
						case 'interview_list':
							this.handleClick('/personal/JobManagement/PersonalInterview')
							break
						case 'interview_list_video':
							this.handleClick('/personal/JobManagement/VideoInterview')
							break
						case 'apply_list':
							this.handleClick('/personal/JobManagement/JobApply')
							break
						case 'ordershow':
							this.handleClick('/commonViews/service/OrderList')
							break
						case 'joblist':
							this.handleClick('/views/JobList')
							break
						case 'resumeedit':
							this.handleClick('/personal/EditResume')
							break
						case 'im':
							// this.handleClick('/views/im/ImList')
							this.handleTips()
							break
						case 'recommend_joblist':
							this.handleClick('/personal/Recommend')
							break
						default:
							break
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box_1 {
		.item {
			width: 100%;
			background-color: #ffffff;
			overflow: hidden;
			border-bottom: 1px solid #f3f3f3;
			padding: 10px 0 0;

			.content {
				width: 100%;
				padding: 0 29px;

				.c2 {
					position: relative;
					font-size: 14px;
					color: #333333;
					padding: 11px 5px;
					border-top: 1px solid #f8f8f8;

					&::after {
						position: absolute;
						right: 3px;
						top: 17px;
						width: 7px;
						height: 7px;
						border-top: 1px solid #999999;
						border-right: 1px solid #999999;
						transform: rotate(45deg);
						content: "";
					}
				}

				.c1 {
					padding: 6px 5px;
					line-height: 1.7;
					word-break: break-all;
					font-size: 14px;
					color: #333333;
				}
			}

			.title {
				position: relative;
				background-color: #fbfbfb;
				font-size: 15px;
				color: #333333;
				padding: 12px 18px;
				font-weight: bold;
				margin: 0 15px;

				.right_txt {
					position: absolute;
					right: 18px;
					top: 50%;
					transform: translate(0, -50%);
					font-size: 14px;
					color: #999999;
				}
			}
		}

		width: 100%;
	}
</style>
